package com.naldo.goodcard;

import java.util.List;

import com.naldo.goodcard.SQL.Cartao;

import android.app.Activity;
import android.database.SQLException;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import com.naldo.goodcard.SQL.*;

public class AddCardActivity extends Activity implements OnClickListener {
	Button btn_gravar;
	RadioButton rbPlus;
	RadioButton rbPremium;
	EditText txtNumero;
	EditText txtCPF;
	
	DbAdapter datasource;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add);
		
		this.btn_gravar = (Button)findViewById(R.id.btGravar);
		this.rbPlus = (RadioButton)findViewById(R.id.rbPlus);
		this.rbPremium = (RadioButton)findViewById(R.id.rbPremium);
		this.txtNumero = (EditText)findViewById(R.id.txtNumero);
		this.txtCPF = (EditText)findViewById(R.id.txtCPF);

		this.btn_gravar.setOnClickListener(this);
	}
	
    @Override
    public void onClick(View v) {
        if(v == this.btn_gravar) {
    		
        	this.datasource = new DbAdapter(this);
    		
    		this.rbPlus = (RadioButton)findViewById(R.id.rbPlus);
    		this.rbPremium = (RadioButton)findViewById(R.id.rbPremium);
    		this.txtNumero = (EditText)findViewById(R.id.txtNumero);
    		this.txtCPF = (EditText)findViewById(R.id.txtCPF);
    		
    		Cartao cartao = new Cartao();
    		
    		if(rbPlus.isChecked())
    		{
    			cartao.setTipo("P");
    		}
    		
    		if(rbPremium.isChecked())
    		{
    			cartao.setTipo("B");
    		}
    		
    		cartao.setNumero(txtNumero.getText().toString());
    		cartao.setCPF(txtCPF.getText().toString());

    		cartao = datasource.createCartao(cartao);
       		
            finish();            
        }
    }
    
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		//getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
